import pymysql
import os

class MySQLDatabase:
    def __init__(self):
        self.host = "localhost"
        self.database = "zmj_data"
        self.user = "root"
        self.password = os.getenv('MPWD')
        if self.password is None:
            self.password = 'jmai4nd@9xT'
        self.connection = None

    def connect(self):
        """Connect to the MySQL database."""
        try:
            self.connection = pymysql.connect(
                host=self.host,
                database=self.database,
                user=self.user,
                password=self.password
            )
            return self.connection
        except pymysql.MySQLError as e:
            print(f"Connected to MySQL database Error: {e}")
            self.connection = None